<template>
    <CommonModal v-model:show="modalShow" :title="modalTitle" @onSubmit="onSubmit" style="width: 600px">
        <n-form
        ref="modalFormRef"
        :model="modalForm"
        :inline="false"
        :rules="rules">
      <n-grid :cols="24" :x-gap="24">
        <n-form-item-gi :span="24" label="资源类型" path="type" hidden>
          <n-select :options="remoteResourceType" v-model:value="modalForm.type">
          </n-select>
        </n-form-item-gi>
        <n-form-item-gi :span="24" label="资源名称" path="resourceName">
          <n-input v-model:value="modalForm.resourceName" clearable placeholder="请输入资源名称"/>
        </n-form-item-gi>
        <n-form-item-gi :span="24" label="是否公开" path="isPublic">
          <n-select :options="isPublicOption" v-model:value="modalForm.isPublic">
          </n-select>
        </n-form-item-gi>

        <n-form-item-gi :span="24" label="API地址" path="apiPath">
          <n-input v-model:value="modalForm.apiPath" clearable placeholder="请输入API路径"/>
        </n-form-item-gi>

        <n-form-item-gi :span="24" label="APIKey" path="apiKey">
          <n-input v-model:value="modalForm.apiKey" clearable placeholder="请输入APIKey"/>
        </n-form-item-gi>

        <n-form-item-gi :span="24" label="反向代理地址" path="reverseProxy">
          <n-input v-model:value="modalForm.reverseProxy" clearable placeholder="请输入反向代理地址"/>
        </n-form-item-gi>

        <n-form-item-gi :span="12" label="Http代理IP" path="httpProxyIp">
          <n-input v-model:value="modalForm.proxyIp" clearable  placeholder="请输入代理IP"/>
        </n-form-item-gi>

        <n-form-item-gi :span="12" label="Http代理端口" path="httpProxyPort">
          <n-input v-model:value="modalForm.proxyPort" clearable  placeholder="请输入代理端口"/>
        </n-form-item-gi>

        <n-form-item-gi :span="8" label="默认资源" path="isDefault">
          <n-radio-group
              v-model:value="modalForm.isDefault"
              name="left-size"
              style="margin-bottom: 12px"
              default-value="0"
          >
            <n-radio-button value="1">
              是
            </n-radio-button>
            <n-radio-button value="0">
              否
            </n-radio-button>
          </n-radio-group>
        </n-form-item-gi>

        <n-form-item-gi :span="8" label="分钟最大请求数" path="maxRequest">
          <n-input-number v-model:value="modalForm.maxRequest"></n-input-number>
        </n-form-item-gi>

        <n-form-item-gi :span="8" label="最大请求时间间隔" path="maxRequestSecond">
          <n-input-number v-model:value="modalForm.maxRequestSecond"></n-input-number>
        </n-form-item-gi>



        <n-form-item-gi :span="8" label="IP每分钟最大请求数" path="ipMaxRequest">
          <n-input-number v-model:value="modalForm.ipMaxRequest"  clearable  >
            <template #suffix>
              次
            </template>
          </n-input-number>
        </n-form-item-gi>
        <n-form-item-gi :span="8" label="IP最大请求时间间隔" path="ipMaxRequestSecond">
          <n-input-number v-model:value="modalForm.ipMaxRequestSecond"   clearable >
            <template #suffix>
              毫秒
            </template>
          </n-input-number>
        </n-form-item-gi>
        <n-form-item-gi :span="8" label="上下文限制对话数" path="limitQuestionContextCount">
          <n-input-number v-model:value="modalForm.limitQuestionContextCount"   clearable >
            <template #suffix>
              轮
            </template>
          </n-input-number>
        </n-form-item-gi>



      </n-grid>
    </n-form>
    </CommonModal>
</template>

<script lang="ts">
import {defineComponent} from "vue";
import CommonModal from "@/components/commonModal/index.vue";
import {useCommonModal} from "@/components/commonModal/useCommonModal";
import { resourceController } from "@/api/resource/resourceController.api";
import {remoteResourceType,isPublicOption} from '@/views/resource'
export default defineComponent({
    name: "UserEditForm",
    components: {
        CommonModal,remoteResourceType,isPublicOption
    },
    setup() {
        const {
            modalShow,
            modalTitle,
            modalForm,
            modalFormRef,
            modalLoading,
            onAdd,
            onEdit,
            onSubmit,
            onDeleteById,
            onDeleteByIds
        } = useCommonModal("ChatGPT", {
                type:'ChatGPT',
                apiPath: "https://api.openai.com/",
                isDefault: "0"
            },
            resourceController.addSDResource,
            resourceController.updateResource,resourceController.deleteResource,resourceController.deleteBatch
        )


        const rules = {

            resourceName: {type: "string", required: true, message: "请输入资源名称", trigger: ["blur", "change"]},
            apiPath: {type: "string", required: true, message: "请输入API地址", trigger: ["blur", "change"]},
            apiKey: {type: "string", required: true, message: "请输入APIKey", trigger: ["blur", "change"]},
            userName: {type: "string", required: true, message: "请输入用户名", trigger: ["input", "blur"]},
            nickName: {type: "string", required: true, message: "请输入用户昵称", trigger: ["input", "blur"]},
        }


        return {
            modalShow,
            modalTitle,
            modalForm,
            modalFormRef,
            modalLoading,
            rules,
            remoteResourceType,
            isPublicOption,
            onAdd,
            onEdit,
            onSubmit,
            onDeleteById,
            onDeleteByIds
        }
    }
})
</script>

<style scoped>

</style>
